package com.xm.shop.pojo.entity;

import io.swagger.annotations.ApiModel;

import java.math.BigDecimal;

/**
 * @author ludi
 * @date:2020/8/30 21:54
 * @description:购物车类
 */
@ApiModel(value = "购物车对象")
public class Cart {
    private Integer cartId;
    private Integer productId;
    private Integer num;
    private BigDecimal totalPrice;
    private Integer userId;
    private Product product;

    public Cart() {
    }

    public Cart(Integer cartId, Integer productId, Integer num,
                BigDecimal totalPrice, Integer userId, Product product) {
        this.cartId = cartId;
        this.productId = productId;
        this.num = num;
        this.totalPrice = totalPrice;
        this.userId = userId;
        this.product = product;
    }

    public Integer getCartId() {
        return cartId;
    }

    public void setCartId(Integer cartId) {
        this.cartId = cartId;
    }

    public Integer getProductId() {
        return productId;
    }

    public void setProductId(Integer productId) {
        this.productId = productId;
    }

    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num = num;
    }

    public BigDecimal getTotalPrice() {
        //取出对应商品的价格和数量
        BigDecimal productPrice = product.getPrice();
        BigDecimal productNum = new BigDecimal(this.num);
        //返回总额
        return productPrice.multiply(productNum);
    }

    public void setTotalPrice(BigDecimal totalPrice) {
        this.totalPrice = totalPrice;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    @Override
    public String toString() {
        return "Cart{" +
                "cartId=" + cartId +
                ", productId=" + productId +
                ", num=" + num +
                ", totalPrice=" + totalPrice +
                ", userId=" + userId +
                ", product=" + product +
                '}';
    }
}
